// 1.引入文件fs模块
const fs = require('fs');

// 2.查看文件信息：fs.statSync( path )
let res = fs.statSync('./demo');
console.log(res);

// isFile(): 是否为文件
console.log( res.isFile() ); // false
// isDirectory(): 是否为文件夹
console.log( res.isDirectory() ); // true


// 3.不存在该文件
console.log(111111111111);
// 同步错误的处理，使用try-catch
try{
    let res2 = fs.statSync('demo/b.js');
    console.log(res2);
}catch(err){
    // try中的代码出现错误，执行catch中的代码，不出错不执行
    console.log(err, '失败信息');
    console.log('文件信息读取失败');
}

console.log(22222222222);
/* 
{
  dev: 1099078830,
  mode: 16822,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 562949953428609,
  size: 0,
  blocks: 0,
  atimeMs: 1684131933096.4492,   
  mtimeMs: 1684131933096.4492,
  ctimeMs: 1684131933096.4492,
  birthtimeMs: 1684131928753.2007,
  atime: 2023-05-15T06:25:33.096Z,
  mtime: 2023-05-15T06:25:33.096Z,
  ctime: 2023-05-15T06:25:33.096Z,
  birthtime: 2023-05-15T06:25:28.753Z
}
*/